#include "pesi_string.h"

namespace PESI {
// http://www.thescripts.com/forum/thread127512.html
  
  // return modified string ``s'' with spaces trimmed from left
  std::string& triml(std::string& s)
  {
    int pos(0);
    for ( ; s[pos]==' ' || s[pos]=='\t' || s[pos] == '\n'; ++pos );
    s.erase(0, pos);
    return s;
  }

  // return modified string ``s'' with spaces trimmed from right
  std::string& trimr(std::string& s)
  {
    int pos(s.size());
    for ( ; pos && (s[pos-1]==' ' || s[pos-1]=='\t' || s[pos-1] == '\n'); --pos );
    s.erase(pos, s.size()-pos);
    return s;
  }

  // return modified string ``s'' with spaces trimmed from edges
  std::string& trim(std::string& s)
  {
    return triml(trimr(s));
  }
}
